package com.open.exam.mapper;

import com.open.exam.databasemodel.ExamApp;
import com.open.exam.sqlprovider.ExamAppProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author naicha
 * Created on 2017/11/7.
 */
@Mapper
public interface ExamAppMapper {

    @Insert("INSERT INTO ExamApp (\n" +
            "\tAppID,\n" +
            "\tAppName,\n" +
            "\tAppCode,\n" +
            "\tmanagerName,\n" +
            "\tmanagerPhone\n" +
            ") SELECT\n" +
            "\t#{appID},\n" +
            "\t#{appName},\n" +
            "\t#{appCode},\n" +
            "\t#{managerName},\n" +
            "\t#{managerPhone}\n" +
            "FROM\n" +
            "\tDUAL\n" +
            "WHERE\n" +
            "\tNOT EXISTS (\n" +
            "\t\tSELECT\n" +
            "\t\t\t1\n" +
            "\t\tFROM\n" +
            "\t\t\tExamApp\n" +
            "\t\tWHERE\n" +
            "\t\t\tAppID = #{appID}\n" +
            "\t);")
    Integer insertExamApp(ExamApp examApp);

    @Select("SELECT * FROM ExamApp")
    List<ExamApp> finaAllExamApp();

    @Update("UPDATE ExamApp SET AppName = #{appName},AppUrl = #{appUrl},AppFTPUrl = #{appFTPUrl},LogoName = #{logoName} WHERE AppId = #{appID}")
    Integer updateExamApp(ExamApp examApp);

    @SelectProvider(type = ExamAppProvider.class,method = "getApp")
    List<ExamApp> getApp(@Param(value = "siteId") String siteId);
}
